package com.tom.convertor;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class DateConvertor implements Converter<String, Date> {

    public Date convert(String sourse) {
        Date result = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            result = simpleDateFormat.parse(sourse);
            System.out.println("日期转换结果是:" + result);
            return result;
        } catch (Exception e) {
            System.out.println("日期转换异常:" + e.getMessage());
        }
        return result;
    }
}
